unit u_Filtro;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxCore, dxButton, StdCtrls, Buttons, Mask, JvExMask, JvToolEdit,
  ExtCtrls, JvExExtCtrls, JvBevel, MMJPanel;

type
  Tf_Filtro = class(TForm)
    MMJPanel2: TMMJPanel;
    lbl3: TLabel;
    JvBevel1: TJvBevel;
    lbl4: TLabel;
    lbl5: TLabel;
    cbbSituacao: TComboBox;
    JvDateEdit1: TJvDateEdit;
    JvDateEdit2: TJvDateEdit;
    edtNomeFrete: TEdit;
    lbl7: TLabel;
    btn5: TBitBtn;
    edtPlaca: TEdit;
    lbl8: TLabel;
    edtNPF: TEdit;
    lbl9: TLabel;
    btnFiltro: TdxButton;
    btnSair: TdxButton;
    edtIdFrete: TEdit;
    procedure btnFiltroClick(Sender: TObject);
    procedure btn5Click(Sender: TObject);
    procedure btnSairClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_Filtro: Tf_Filtro;

implementation

uses UDM, uProcurar, u_Busca, u_BuscaBal;

{$R *.dfm}

procedure Tf_Filtro.btnFiltroClick(Sender: TObject);
begin
  if ((DM.TELA = 'BALANCAFRUTA') or (DM.TELA = 'PRINCIPAL')) then
  begin
    f_Busca.v_Situacao := cbbSituacao.Text;
    f_Busca.v_Dta1 := JvDateEdit1.Text;
    f_Busca.v_Dta2 := JvDateEdit2.Text;
    f_Busca.v_NPF := edtNPF.Text;
    f_Busca.v_IDFretista := edtIdFrete.Text;
    f_Busca.v_Placa := edtPlaca.Text;
  end;
  if (DM.TELA = 'BALANCA') then
  begin
    f_BuscaBal.v_Situacao := cbbSituacao.Text;
    f_BuscaBal.v_Dta1 := JvDateEdit1.Text;
    f_BuscaBal.v_Dta2 := JvDateEdit2.Text;
    f_BuscaBal.v_NPF := edtNPF.Text;
    f_BuscaBal.v_IDFretista := edtIdFrete.Text;
    f_BuscaBal.v_Placa := edtPlaca.Text;
  end;
  Close;
end;

procedure Tf_Filtro.btn5Click(Sender: TObject);
begin
  fProcurar:= TfProcurar.Create(self,dm.buscaMotorista);
  fProcurar.btnImprimir.Visible := true;
  fProcurar.RadioGroup1.Visible := true;
  fProcurar.BtnProcurar.Click;
  fProcurar.EvDBFind1.DataField := 'NOMETRANSP';
  fProcurar.RadioGroup2.Visible := True;
  try
   if fProcurar.ShowModal=mrOk then
    begin
      edtIdFrete.Text   := IntToStr(dm.buscaMotoristaCODTRANSP.AsInteger);
      edtNomeFrete.Text := dm.buscaMotoristaNOMETRANSP.AsString;
      edtPlaca.Text     := dm.buscaMotoristaPLACATRANSP.AsString;
    end;
  finally
    DM.buscaMotorista.Close;
    fProcurar.Free;
  end;
end;

procedure Tf_Filtro.btnSairClick(Sender: TObject);
begin
   Close;
end;

procedure Tf_Filtro.FormShow(Sender: TObject);
begin
   cbbSituacao.Text := '';
   JvDateEdit1.Text := '';
   JvDateEdit2.Text := '';
   edtNPF.Text := '';
   edtIdFrete.Text := '';
   edtNomeFrete.Text := '';
   edtPlaca.Text := '';
end;

end.
